1 DATA

## Longitudinal data
data_sum <- loadlongitudinaldata(dataset = "DATA_Adults_G1G29.csv", rm_generation1 = 1,rm_generation2 = 7,rm_generation3 = 29)

## Phenotyping steps
data_G0 <- loadfitnessdata(dataset = "Selection_Phenotypage_G0_G7_G8.csv", generation = "G1")
data_G7 <- loadfitnessdata(dataset = "Selection_Phenotypage_G0_G7_G8.csv", generation = "G7")
data_G29 <- loadfitnessdata(dataset = 
                            "PERFORMANCE_Comptage_adultes_G13G14G15G16G17G18G19G20G21G22G23G24G25G26G27G28G29.csv",
                            generation = "29")


#Compute log change
data_logchange<-computelogchange(fitness_dataset_intermediate = data_G7, fitness_dataset_final = data_G29)
#Lines: CE2 and CR2 do not pass Geary's test (the threshold of a standardized mean greater than 3)
data_logchange$Line_type  <- ifelse(data_logchange$Line == "CR2"| data_logchange$Line == "CE2", "solid","dashed")


#Formatting for plotting pairwise of fitness difference
EC_Cran_Cher_G7<-formattingplotpair(data_logchange, "7", "Cherry", "Cranberry")
EC_Straw_Cran_G7<-formattingplotpair(data_logchange, "7", "Cranberry", "Strawberry")
EC_Straw_Cher_G7<-formattingplotpair(data_logchange, "7", "Strawberry", "Cherry")
EC_Cran_Cher_G29<-formattingplotpair(data_logchange, "29", "Cherry", "Cranberry")
EC_Straw_Cran_G29<-formattingplotpair(data_logchange, "29", "Cranberry", "Strawberry")
EC_Straw_Cher_G29<-formattingplotpair(data_logchange, "29", "Strawberry", "Cherry")


#Formatting for plot pool
TEMP_dataG29_CheCran <- formattinglogchange(data_logchange, "29", "Cherry", "Cranberry")
TEMP_dataG29_CranStraw <- formattinglogchange(data_logchange, "29", "Cranberry", "Strawberry")
TEMP_dataG29_StrawChe <- formattinglogchange(data_logchange, "29", "Strawberry", "Cherry")

2 SUP: Pairwise of Fitness difference

2.1 Plot

#Limit axis 
lim_G7<-max(abs(min(data_logchange[data_logchange$Generation=="7",]$logchange-
                      1.96*data_logchange[data_logchange$Generation=="7",]$sd_logchange, na.rm = T)),
            max(data_logchange[data_logchange$Generation=="7",]$logchange+
                  1.96*data_logchange[data_logchange$Generation=="7",]$sd_logchange, na.rm = T))

lim_G29<-max(abs(min(data_logchange[data_logchange$Generation=="29",]$logchange-
                       1.96*data_logchange[data_logchange$Generation=="29",]$sd_logchange, na.rm = T)),
            max(data_logchange[data_logchange$Generation=="29",]$logchange+
                  1.96*data_logchange[data_logchange$Generation=="29",]$sd_logchange, na.rm = T))

#Plot
PAIR_StrawCran_G7<-ggplot(data = EC_Straw_Cran_G7,
                          aes(x = logchange_Strawberry,y = logchange_Cranberry, color=Fruit_s)) +
  geom_errorbar(aes(ymin = logchange_Cranberry-1.96*sd_logchange_Cranberry,
                    ymax = logchange_Cranberry+1.96*sd_logchange_Cranberry, linetype=Line_type),
                width=0.02,size=0.2,alpha=1) + 
  geom_errorbarh(aes(xmin = logchange_Strawberry-1.96*sd_logchange_Strawberry,
                     xmax = logchange_Strawberry+1.96*sd_logchange_Strawberry, linetype=Line_type),
                 height=0.02,size=0.2,alpha=1) + 
  geom_point(shape=21, size=3,  fill = "#ffffff", stroke=1.3) + 
  xlab("Fitness difference\nin strawberry")  +     
  ylab("Fitness difference\nin cranberry")  +
  xlim(-lim_G7,lim_G7) + 
  ylim(-lim_G7,lim_G7) +  
  scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96"))  + 
  theme(axis.title.x = element_text(size=10, colour = "#3FAA96"),
        axis.title.y = element_text(size=10, colour = "#FDB424")) +
  theme_LO_sober
 PAIR_StrawCran_G7

PAIR_StrawChe_G7<-ggplot(data = EC_Straw_Cher_G7,
                         aes(x = logchange_Cherry,y = logchange_Strawberry, color=Fruit_s)) + 
  geom_errorbar(aes(ymin = logchange_Strawberry-1.96*sd_logchange_Strawberry,
                    ymax = logchange_Strawberry+1.96*sd_logchange_Strawberry, linetype=Line_type),
                  width=0.02, size=0.2, alpha=1) + 
  geom_errorbarh(aes(xmin = logchange_Cherry-1.96*sd_logchange_Cherry,
                     xmax = logchange_Cherry+1.96*sd_logchange_Cherry, linetype=Line_type),
                  height=0.02, size=0.2, alpha=1) + 
  geom_point(shape=21, size=3,  fill = "#ffffff", stroke=1.3) + 
  ylab("Fitness difference\nin strawberry")  + 
  xlab("Fitness difference\nin cherry")  + 
  scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96"))  + 
  xlim(-lim_G7,lim_G7) + 
  ylim(-lim_G7,lim_G7) +    
  theme(axis.title.x = element_text(size=10, colour = "#BC3C6D"),
           axis.title.y = element_text(size=10, colour = "#3FAA96")) +
  theme_LO_sober
 PAIR_StrawChe_G7

PAIR_CheCran_G7<-ggplot(data = EC_Cran_Cher_G7,aes(x = logchange_Cranberry,y = logchange_Cherry, 
                                          color=Fruit_s)) + 
  geom_errorbar(aes(ymin = logchange_Cherry-1.96*sd_logchange_Cherry,
                      ymax = logchange_Cherry+1.96*sd_logchange_Cherry, linetype=Line_type),
                  width=0.02, size=0.2, alpha=1) + 
  geom_errorbarh(aes(xmin = logchange_Cranberry-1.96*sd_logchange_Cranberry,
                       xmax = logchange_Cranberry+1.96*sd_logchange_Cranberry, linetype=Line_type),
                  height=0.02, size=0.2, alpha=1) + 
  geom_point(shape=21, size=3,  fill = "#ffffff", stroke=1.3) + 
  ylab("Fitness difference\nin cherry")  + 
  xlab("Fitness difference\nin cranberry")  + 
  xlim(-lim_G7, lim_G7) + 
  ylim(-lim_G7, lim_G7) +     
  scale_color_manual(values = c("#BC3C6D", "#FDB424", "#3FAA96"))  + 
  theme_LO_sober + 
  theme(axis.title.x = element_text(colour = "#FDB424"),
        axis.title.y = element_text(colour = "#BC3C6D")) 
 PAIR_CheCran_G7

################## Final phenotyping step
#Plot
PAIR_CranStraw_G29<-ggplot(data = EC_Straw_Cran_G29,
                          aes(x = logchange_Strawberry, y = logchange_Cranberry,  color=Fruit_s)) + 
  geom_errorbar(aes(ymin = logchange_Cranberry-1.96*sd_logchange_Cranberry,
                      ymax = logchange_Cranberry+1.96*sd_logchange_Cranberry, linetype=Line_type),
                  width=0.02,size=0.2,alpha=1) + 
  geom_errorbarh(aes(xmin = logchange_Strawberry-1.96*sd_logchange_Strawberry,
                       xmax = logchange_Strawberry+1.96*sd_logchange_Strawberry, linetype=Line_type),
                  height=0.02,size=0.2,alpha=1) + 
  geom_point(aes(fill = Fruit_s),shape=21, size=3) + 
  xlab("Fitness difference\nin strawberry")  +     
  ylab("Fitness difference\nin cranberry")  +
  xlim(-lim_G29,lim_G29) + 
  ylim(-lim_G29,lim_G29) +     
  scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96"))  + 
  scale_fill_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96"))  + 
  theme(axis.title.x = element_text(size=10, colour = "#3FAA96"),
        axis.title.y = element_text(size=10, colour = "#FDB424")) +
  theme_LO_sober
 PAIR_CranStraw_G29

PAIR_StrawChe_G29<-ggplot(data = EC_Straw_Cher_G29,
                         aes(x = logchange_Cherry,y = logchange_Strawberry,  color=Fruit_s)) + 
  geom_errorbar(aes(ymin = logchange_Strawberry-1.96*sd_logchange_Strawberry,
                      ymax = logchange_Strawberry+1.96*sd_logchange_Strawberry, linetype=Line_type),
                  width=0.02,size=0.2,alpha=1) + 
  geom_errorbarh(aes(xmin = logchange_Cherry-1.96*sd_logchange_Cherry,
                       xmax = logchange_Cherry+1.96*sd_logchange_Cherry, linetype=Line_type),
                  height=0.02,size=0.2,alpha=1) + 
  geom_point(aes(fill = Fruit_s),shape=21, size=3) + 
  ylab("Fitness difference\nin strawberry")  + 
  xlab("Fitness difference\nin cherry")  + 
  scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96"))  + 
  scale_fill_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96"))  + 
  xlim(-lim_G29,lim_G29) + 
  ylim(-lim_G29,lim_G29) +       
  theme(axis.title.x = element_text(colour = "#BC3C6D"),
           axis.title.y = element_text(colour = "#3FAA96")) +
  theme_LO_sober
 PAIR_StrawChe_G29

PAIR_CheCran_G29<-ggplot(data = EC_Cran_Cher_G29,
                         aes(x = logchange_Cranberry,y = logchange_Cherry, color=Fruit_s)) + 
  geom_errorbar(aes(ymin = logchange_Cherry-1.96*sd_logchange_Cherry,
                      ymax = logchange_Cherry+1.96*sd_logchange_Cherry, linetype=Line_type),
                  width=0.02,size=0.2,alpha=1) + 
  geom_errorbarh(aes(xmin = logchange_Cranberry-1.96*sd_logchange_Cranberry,
                       xmax = logchange_Cranberry+1.96*sd_logchange_Cranberry, linetype=Line_type),
                  height=0.02,size=0.2,alpha=1) + 
  geom_point(aes(fill = Fruit_s), shape=21, size=3) + 
  ylab("Fitness difference\nin cherry")  + 
  xlab("Fitness difference\nin cranberry")  + 
  xlim(-lim_G29,lim_G29) + 
  ylim(-lim_G29,lim_G29) +   
  scale_fill_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96"))  + 
  scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96"))  + 
  theme_LO_sober + 
  theme(axis.title.x = element_text(colour = "#FDB424"),
        axis.title.y = element_text(colour = "#BC3C6D")) 
 PAIR_CheCran_G29

 #Legend
TEMP_data_logchange_sum_Straw_Cher_G7<-data_logchange
TEMP_data_logchange_sum_Straw_Cher_G7$Pheno<-sample(c("Intermediate", "Final"),
                                                    length(data_logchange$logchange), 
                                                    replace=TRUE)

PAIR_plot_legend<- ggplot(data=TEMP_data_logchange_sum_Straw_Cher_G7, 
                          aes(x=Treatment, y=logchange, group=Fruit_s, colour=Fruit_s,shape=Pheno)) +
  geom_errorbar(aes(ymin=logchange-1.96*sd_logchange, ymax=logchange+1.96*sd_logchange),
                  width=0.01,size=1) +
  geom_point(size=3, stroke=1.3) + 
  scale_shape_manual(name = "Phenotyping step", 
                     labels = c("Intermediate", "Final"),values=c(21,16)) +
  scale_color_manual(name= "Selection fruit", 
                     values=c("#BC3C6D", "#FDB424", "#3FAA96"), 
                     label=c("Cherry", "Cranberry", "Strawberry")) +   
  theme_LO_sober
PAIR_legend<-lemon::g_legend(PAIR_plot_legend)

rm(TEMP_data_logchange_sum_Straw_Cher_G7)




PAIR_Fig_Sup <-  cowplot::ggdraw() +
  cowplot::draw_plot(PAIR_CheCran_G7+theme(legend.position = "none"), 
            x =0.00, y = 0.5, width = 0.22, height =0.45) +
  cowplot::draw_plot(PAIR_StrawCran_G7+theme(legend.position = "none"), 
            x = 0.26, y = 0.5, width = 0.22, height = 0.45) +
  cowplot::draw_plot(PAIR_StrawChe_G7+theme(legend.position = "none"), 
            x = 0.52, y = 0.5, width = 0.22, height = 0.45) + 
  cowplot::draw_plot(PAIR_legend, x = 0.80, y = 0.5, width = 0.1, height = 0.1) +
  cowplot::draw_plot(PAIR_CheCran_G29+theme(legend.position = "none"), 
            x =0.00, y = 0, width = 0.22, height = 0.45) +
  cowplot::draw_plot(PAIR_CranStraw_G29+theme(legend.position = "none"), 
            x = 0.26, y = 0, width = 0.22, height = 0.45) +
  cowplot::draw_plot(PAIR_StrawChe_G29+theme(legend.position = "none"), 
            x = 0.52, y = 0, width = 0.22, height = 0.45) + 
  cowplot::draw_plot_label(c("Intermediate phenotyping step", "A", "B", "C", " ",
                    "Final phenotyping step", "D", "E", "F", " "),  
                  x = c(0.26,0,0.26,0.52,0.82,0.2,0,0.26,0.52,0.82), 
                  y = c(1.01,0.97,0.97,0.97,0.97,0.5,0.47, 0.47, 0.47, 0.47), 
                  hjust = c(-0.25,-0.25,-0.25,-0.25,-0.25,-0.75,-0.75,-0.75,-0.75,-0.75), 
                  vjust = c(1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5),
                  size = 14) 
 PAIR_Fig_Sup

cowplot::save_plot(file=here::here("figures", "SUPMAT_LogChange_Pairwise.pdf"), PAIR_Fig_Sup, 
                   base_height = 15/cm(1), base_width = 30/cm(1), dpi = 610)

3 SUP: Long vs Fitness

3.1 Data

#To consider fruit maternal effect and GF maternal effect: new plot 
## Y-axis = log change = log(Fitness pheno)-log(fitness initial)
## X-axis = fitness temp / fitness initial
 ## example: for CEA during first phase 
    ## log(mean (CE1 from G2 to G5) / mean (Cherry G2))

##To check with Nico: for x-axis: denominator=mean Cherry G2 or mean CE1 G2 (???????????)


####### Phenotyping steps 
#Compute log change
data_logchange <- computelogchange(fitness_dataset_intermediate = data_G7, fitness_dataset_final = data_G29)

#Remove allopatric data
data_fitness_pheno <- data_logchange[data_logchange$SA==1,]
data_fitness_pheno <- data_fitness_pheno[, c("Line", "Fruit_s", "logchange", "sd_logchange")]


####### Longitudinal data 
#Compute log change
data_logchange_long <- computelogchange_forlongdata(longitudinal_dataset = data_sum)


####### Merge data
data_compare_longitudinal_pheno <- merge(data_logchange_long,data_fitness_pheno,by=c("Line", "Fruit_s"))
data_compare_longitudinal_pheno <- droplevels(data_compare_longitudinal_pheno)

## Does not seem to be a correlation between measures
cor.test(data_compare_longitudinal_pheno$logchange[data_compare_longitudinal_pheno$Phase=="first_prepool"], data_compare_longitudinal_pheno$logchange_long[data_compare_longitudinal_pheno$Phase=="first_prepool"])
## 
##  Pearson's product-moment correlation
## 
## data:  data_compare_longitudinal_pheno$logchange[data_compare_longitudinal_pheno$Phase == "first_prepool"] and data_compare_longitudinal_pheno$logchange_long[data_compare_longitudinal_pheno$Phase == "first_prepool"]
## t = 0.56297, df = 12, p-value = 0.5838
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.4046042  0.6367930
## sample estimates:
##       cor 
## 0.1604117
cor.test(data_compare_longitudinal_pheno$logchange[data_compare_longitudinal_pheno$Phase=="second_postpool"], data_compare_longitudinal_pheno$logchange_long[data_compare_longitudinal_pheno$Phase=="second_postpool"])
## 
##  Pearson's product-moment correlation
## 
## data:  data_compare_longitudinal_pheno$logchange[data_compare_longitudinal_pheno$Phase == "second_postpool"] and data_compare_longitudinal_pheno$logchange_long[data_compare_longitudinal_pheno$Phase == "second_postpool"]
## t = 0.86532, df = 9, p-value = 0.4093
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.3870859  0.7519973
## sample estimates:
##       cor 
## 0.2771425
####### Geary test
#Lines: CE2 and CR2 do not pass Geary's test (the threshold of a standardized mean greater than 3)
data_compare_longitudinal_pheno$Line_type  <- ifelse(data_compare_longitudinal_pheno$Line == "CR2"|
                                                       data_compare_longitudinal_pheno$Line == "CE2", "solid","dashed")

3.2 Plot long vs fitness

PLOT_IntermediatePheno_LOGCHANGE<-ggplot(data=data_compare_longitudinal_pheno[data_compare_longitudinal_pheno$Phase=="first_prepool",], 
       aes(y=logchange,x=logchange_long, color=Fruit_s,shape=Fruit_s, linetype=Line_type)) +
  geom_errorbar(aes(x = logchange_long, 
                    ymin = logchange-(1.96*sd_logchange), 
                    ymax = logchange+(1.96*sd_logchange)),
                  width=0.02,size=0.2,alpha=1) +
  geom_errorbarh(aes(y = logchange, 
                    xmin = logchange_long-1.96*sd_logchange_long,
                    xmax = logchange_long+1.96*sd_logchange_long),
                 height=0.02,size=0.2,alpha=1) +
  geom_point(size=3, fill = "#ffffff", stroke=1.3) +
  scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) + 
  scale_shape_manual(values=c(21, 22, 24)) + 
  xlab("Fitness difference between average fitness across generations 13 to 26\nand average fitness across generations 2 to 5") + 
  ylab("Fitness difference between\nintermediate and initial phenotyping steps") + 
  labs(color="Selection fruit", shape="Selection fruit") + 
  geom_abline(intercept = 0, slope = 1, color="black", linetype="dashed", size=0.8) +
  ylim(-1.9,0.9) + 
  xlim(-1.9,0.9) +
  guides(linetype=FALSE) +
  ggtitle("Intermediate phenotyping step vs. Phase 1") +
  theme_LO_sober 
PLOT_IntermediatePheno_LOGCHANGE 

PLOT_FinalPheno_LOGCHANGE <- 
  ggplot(data=data_compare_longitudinal_pheno
                        [data_compare_longitudinal_pheno$Phase=="second_postpool",], 
                        aes(y=logchange, x=logchange_long, 
                            color=Fruit_s, shape=Fruit_s, fill=Fruit_s, linetype=Line_type)) +
  geom_errorbar(aes(x = logchange_long, 
                    ymin = logchange-(1.96*sd_logchange),
                    ymax = logchange+(1.96*sd_logchange)),
                  width=0.02,size=0.2,alpha=1) +
  geom_errorbarh(aes(y = logchange, 
                    xmin = logchange_long-1.96*sd_logchange_long,
                    xmax = logchange_long+1.96*sd_logchange_long),
                 height=0.02,size=0.2,alpha=1) +
  geom_abline(intercept = 0, slope = 1, color="black", 
                 linetype="dashed", size=0.8) +
  geom_point(size=3, stroke=1) +
  scale_fill_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) + 
  scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) + 
  scale_shape_manual(values=c(21, 22, 24)) + 
  xlab("Fitness difference between average fitness across generations 13 to 26\nand average fitness across generations 2 to 5") + 
  ylab("Fitness difference between\nfinal and initial phenotyping steps") + 
  labs(color="Selection fruit", shape="Selection fruit", fill="Selection fruit") + 
  ylim(-0.5,1.7) +
  xlim(-0.5,1.7) +
  guides(linetype=FALSE) +
  ggtitle("Final phenotyping step vs. Phase 3") +
  theme_LO_sober
PLOT_FinalPheno_LOGCHANGE  

PLOT_Comparison_Pheno_Longitudinal_LOGCHANGE <- cowplot::ggdraw() +
  cowplot::draw_plot(PLOT_IntermediatePheno_LOGCHANGE + 
                       theme(axis.title.y = element_text(size=10),
                             axis.title.x = element_text(size=10)),
            x = 0, y = 0.5, width = 1, height = 0.5) +
  cowplot::draw_plot(PLOT_FinalPheno_LOGCHANGE + 
                       theme(axis.title.y = element_text(size=10),
                             axis.title.x = element_text(size=10)),
            x =0, y = 0, width = 1, height = 0.5) +
  cowplot::draw_plot_label(c("A", "B"),  
                  x = c(0,0), y = c(1,0.5), 
                  size = 14) 
PLOT_Comparison_Pheno_Longitudinal_LOGCHANGE

cowplot::save_plot(file=here::here("figures", "SUPMAT_LogChange_Pheno_Longitudinal.pdf"),
                   PLOT_Comparison_Pheno_Longitudinal_LOGCHANGE, base_height = 20/cm(1), base_width = 15/cm(1), dpi = 1200)

3.3 Extra plot Maternal effects

m <- lm(logchange ~ logchange_long + offset(logchange_long),
        data = data_compare_longitudinal_pheno[data_compare_longitudinal_pheno$Phase=="second_postpool",]) 

summary(m)
## 
## Call:
## lm(formula = logchange ~ logchange_long + offset(logchange_long), 
##     data = data_compare_longitudinal_pheno[data_compare_longitudinal_pheno$Phase == 
##         "second_postpool", ])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.33858 -0.19094  0.00374  0.12442  0.46801 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)
## (Intercept)     -0.1419     0.4433  -0.320    0.756
## logchange_long  -0.6261     0.4321  -1.449    0.181
## 
## Residual standard error: 0.2755 on 9 degrees of freedom
## Multiple R-squared:  0.07681,    Adjusted R-squared:  -0.02577 
## F-statistic: 0.7488 on 1 and 9 DF,  p-value: 0.4093
#pval of logchange_long = 0.003 => slope is different of 1 
#pval of Intercept = 0.80 => no evolution of maternal effect?


## Ratio maternal effects derived pop / maternal effect ancestral population 
exp(coef(m)[1]) 
## (Intercept) 
##   0.8677455
# proportion of adaptation due to maternal effects
data_compare_longitudinal_pheno$mateff <- (data_compare_longitudinal_pheno$logchange_long -
  data_compare_longitudinal_pheno$logchange) / data_compare_longitudinal_pheno$logchange_long

data_compare_longitudinal_pheno
##    Line    Fruit_s           Phase logchange_long sd_logchange_long   logchange
## 1   CE1     Cherry   first_prepool    0.052171872        0.04369480 -0.27403677
## 2   CE2     Cherry   first_prepool   -0.141633419        0.05989994 -0.56171884
## 3   CE3     Cherry   first_prepool    0.181479090        0.05900577  0.18528246
## 4   CE4     Cherry   first_prepool    0.112182431        0.03403012  0.12791340
## 5   CEA     Cherry second_postpool    1.286461806        0.03009355  0.14767000
## 6   CEB     Cherry second_postpool    1.271123602        0.02927841  0.25038029
## 7   CEC     Cherry second_postpool    1.328414009        0.02919479  0.35854062
## 8   CR1  Cranberry   first_prepool   -0.106472445        0.06244081  0.26983737
## 9   CR2  Cranberry   first_prepool   -0.131812582        0.02962644 -0.10684877
## 10  CR3  Cranberry   first_prepool    0.223655846        0.04140920  0.05809882
## 11  CR4  Cranberry   first_prepool   -0.005509029        0.05739275  0.35156311
## 12  CR5  Cranberry   first_prepool   -0.128907603        0.07401524  0.18840336
## 13  CRA  Cranberry second_postpool    0.803160627        0.02812570 -0.14885350
## 14  CRB  Cranberry second_postpool    0.916989807        0.02973486  0.29719689
## 15  CRC  Cranberry second_postpool    0.961100074        0.02673814  0.02703717
## 16  CRD  Cranberry second_postpool    0.867039542        0.02951112 -0.15627744
## 17  CRE  Cranberry second_postpool    1.067157543        0.02649123  0.72513486
## 18  FR1 Strawberry   first_prepool    0.292467664        0.03244930  0.33051044
## 19  FR2 Strawberry   first_prepool   -0.344088555        0.06045692  0.09022737
## 20  FR3 Strawberry   first_prepool   -0.014070055        0.02785930  0.13335674
## 21  FR4 Strawberry   first_prepool    0.033908974        0.02627773  0.58063316
## 22  FR5 Strawberry   first_prepool   -0.516039148        0.02443227  0.18650420
## 23  FRA Strawberry second_postpool    0.766018339        0.02732276  0.15709032
## 24  FRB Strawberry second_postpool    0.867962346        0.02567402  0.56023100
## 25  FRC Strawberry second_postpool    0.951223373        0.02672825  0.36640738
##    sd_logchange Line_type       mateff
## 1    0.25731181    dashed   6.25257685
## 2    0.57349396     solid  -2.96600492
## 3    0.11827433    dashed  -0.02095761
## 4    0.24311831    dashed  -0.14022667
## 5    0.15742840    dashed   0.88521229
## 6    0.10098643    dashed   0.80302444
## 7    0.11692997    dashed   0.73009874
## 8    0.21318308    dashed   3.53433998
## 9    0.46435229     solid   0.18938869
## 10   0.13676999    dashed   0.74023116
## 11   0.12714934    dashed  64.81580042
## 12   0.14497197    dashed   2.46153801
## 13   0.11935520    dashed   1.18533465
## 14   0.15311973    dashed   0.67589946
## 15   0.11563812    dashed   0.97186852
## 16   0.11566948    dashed   1.18024257
## 17   0.12754300    dashed   0.32049878
## 18   0.08222221    dashed  -0.13007514
## 19   0.17892718    dashed   1.26222138
## 20   0.16884574    dashed  10.47805368
## 21   0.13295026    dashed -16.12328880
## 22   0.25058617    dashed   1.36141484
## 23   0.14115599    dashed   0.79492616
## 24   0.12842826    dashed   0.35454458
## 25   0.12011698    dashed   0.61480406
#Plot
PLOT_Maternaleffects<-ggplot(data=data_compare_longitudinal_pheno, 
       aes(y=mateff,x=logchange_long, color=Fruit_s, shape=Fruit_s, fill=interaction(Phase,Fruit_s))) +
  geom_point(size=3,  stroke=1.3) +
  scale_fill_manual(name = "Phase", 
                      values = c("#ffffff","#BC3C6D", "#ffffff","#FDB424", "#ffffff", "#3FAA96"), 
                      breaks = c("first_prepool.Cherry", "second_postpool.Cherry"), 
                      labels = c("Phase 1","Phase 3")) +
  scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) + 
  scale_shape_manual(values=c(21, 22, 24)) + 
  xlab("Fitness difference between average fitness\nacross generations 2 to 5 (13 to 26) and generation 2") + 
  ylab("Proportion of adaptation\ndue to evolution of maternal effects") + 
  labs(color="Selection fruit", shape="Selection fruit") + 
  guides(fill = guide_legend(override.aes = list(fill = c("white","black"), shape=21))) +
  theme_LO_sober 
PLOT_Maternaleffects 

cowplot::save_plot(file=here::here("figures", "SUPMAT_Maternal_effects.pdf"),
                   PLOT_Maternaleffects, base_height = 20/cm(1), base_width = 15/cm(1), dpi = 1200)

4 SUP: Adaptation 8fruits

4.1 Longitudinal data

data_sum_allfruits <- loadlongitudinaldata_allfruits(dataset = "DATA_Adults_G1G29.csv", rm_generation_max = 5)
data_sum_allfruits_AN<-data_sum_allfruits[data_sum_allfruits$Generation!=1,]

4.2 Analysis

#Models
mod_all_interaction <- lme4::lmer(fitness ~ Fruit_s*Generation + (1|Generation) + (1|Generation:Fruit_s), 
            weights = N, data = data_sum_allfruits_AN, REML = FALSE)

mod_all_generation<- lme4::lmer(fitness ~ Generation + (1|Generation) + (1|Generation:Fruit_s) , 
            weights = N, data = data_sum_allfruits_AN, REML = FALSE)

mod_all_fruit_generation<- lme4::lmer(fitness ~ Fruit_s+Generation + (1|Generation) + (1|Generation:Fruit_s) , 
            weights = N, data = data_sum_allfruits_AN, REML = FALSE)

mod_all_fruit<- lme4::lmer(fitness ~ Fruit_s + (1|Generation) + (1|Generation:Fruit_s) , 
            weights = N, data = data_sum_allfruits_AN, REML = FALSE)

mod_all_line<- lme4::lmer(fitness ~ Line + (1|Generation) + (1|Generation:Fruit_s), 
            weights = N, data = data_sum_allfruits_AN, REML = FALSE)

mod_all_null<- lme4::lmer(fitness ~ 1  + (1|Generation) + (1|Generation:Fruit_s), 
            weights = N, data = data_sum_allfruits_AN, REML = FALSE)

mod_all_interaction_line_generation <- lme4::lmer(fitness ~ Line*Generation + (1|Generation) + (1|Generation:Fruit_s), 
            weights = N, data = data_sum_allfruits_AN, REML = FALSE)

mod_line_generation <- lme4::lmer(fitness ~ Line+Generation + (1|Generation) + (1|Generation:Fruit_s), 
            weights = N, data = data_sum_allfruits_AN, REML = FALSE)

MuMIn::model.sel(mod_all_interaction,mod_all_fruit_generation,mod_all_fruit,mod_all_null,mod_all_generation,mod_all_line,mod_all_interaction_line_generation,mod_line_generation)
## Model selection table 
##                                       (Int) Frt_s      Gnr Frt_s:Gnr Lin
## mod_all_interaction                 -1.2580     + -0.56070         +    
## mod_all_fruit                       -2.4250     +                       
## mod_all_fruit_generation            -2.3690     + -0.02678              
## mod_all_line                        -2.3980                            +
## mod_line_generation                 -2.1860       -0.08906             +
## mod_all_generation                  -1.8340        0.27440              
## mod_all_null                        -0.9798                             
## mod_all_interaction_line_generation  1.0780       -1.60000             +
##                                     Gnr:Lin             family df   logLik
## mod_all_interaction                         gaussian(identity) 19  -80.610
## mod_all_fruit                               gaussian(identity) 11  -92.408
## mod_all_fruit_generation                    gaussian(identity) 12  -92.306
## mod_all_line                                gaussian(identity) 43  -37.016
## mod_line_generation                         gaussian(identity) 44  -35.790
## mod_all_generation                          gaussian(identity)  5 -112.481
## mod_all_null                                gaussian(identity)  4 -114.217
## mod_all_interaction_line_generation       + gaussian(identity) 72    6.924
##                                      AICc  delta weight
## mod_all_interaction                 208.0   0.00  0.633
## mod_all_fruit                       209.6   1.64  0.279
## mod_all_fruit_generation            211.9   3.98  0.087
## mod_all_line                        220.1  12.14  0.001
## mod_line_generation                 223.5  15.50  0.000
## mod_all_generation                  235.6  27.60  0.000
## mod_all_null                        236.8  28.87  0.000
## mod_all_interaction_line_generation 439.3 231.37  0.000
## Models ranked by AICc(x) 
## Random terms (all models): 
## '1 | Generation', '1 | Generation:Fruit_s'
summary(mod_all_interaction)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: 
## fitness ~ Fruit_s * Generation + (1 | Generation) + (1 | Generation:Fruit_s)
##    Data: data_sum_allfruits_AN
## Weights: N
## 
##      AIC      BIC   logLik deviance df.resid 
##    199.2    250.0    -80.6    161.2       88 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.8179 -0.7264  0.0873  0.6984  2.2653 
## 
## Random effects:
##  Groups             Name        Variance Std.Dev.
##  Generation:Fruit_s (Intercept) 0.000    0.000   
##  Generation         (Intercept) 0.000    0.000   
##  Residual                       1.813    1.346   
## Number of obs: 107, groups:  Generation:Fruit_s, 25; Generation, 4
## 
## Fixed effects:
##                              Estimate Std. Error t value
## (Intercept)                   -1.2579     1.4340  -0.877
## Fruit_sCherry                  0.1344     1.4604   0.092
## Fruit_sCranberry               1.7136     1.4583   1.175
## Fruit_sFig                     1.1471     1.4909   0.769
## Fruit_sGrape                  -3.4559     3.1334  -1.103
## Fruit_sRosehips               -2.6107     1.6847  -1.550
## Fruit_sStrawberry              0.5629     1.4584   0.386
## Fruit_sTomato                 -1.5720     1.7459  -0.900
## Generation                    -0.5607     0.6930  -0.809
## Fruit_sCherry:Generation       0.7404     0.6988   1.060
## Fruit_sCranberry:Generation    0.2725     0.6979   0.391
## Fruit_sFig:Generation          0.2539     0.7097   0.358
## Fruit_sGrape:Generation        1.6698     1.5329   1.089
## Fruit_sRosehips:Generation     1.3420     0.8036   1.670
## Fruit_sStrawberry:Generation   0.6427     0.6980   0.921
## Fruit_sTomato:Generation       1.1111     0.8101   1.371
## convergence code: 0
## boundary (singular) fit: see ?isSingular
#Posthoc
mod_all_interaction <- lme4::lmer(fitness ~ Fruit_s*Generation + (1|Generation) + (1|Generation:Fruit_s), 
            weights = N, data = data_sum_allfruits_AN)
summary(mod_all_interaction)
## Linear mixed model fit by REML ['lmerMod']
## Formula: 
## fitness ~ Fruit_s * Generation + (1 | Generation) + (1 | Generation:Fruit_s)
##    Data: data_sum_allfruits_AN
## Weights: N
## 
## REML criterion at convergence: 184.6
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.59867 -0.66991  0.08051  0.64407  2.08904 
## 
## Random effects:
##  Groups             Name        Variance Std.Dev.
##  Generation:Fruit_s (Intercept) 0.000    0.00    
##  Generation         (Intercept) 0.000    0.00    
##  Residual                       2.132    1.46    
## Number of obs: 107, groups:  Generation:Fruit_s, 25; Generation, 4
## 
## Fixed effects:
##                              Estimate Std. Error t value
## (Intercept)                   -1.2579     1.5550  -0.809
## Fruit_sCherry                  0.1344     1.5836   0.085
## Fruit_sCranberry               1.7136     1.5813   1.084
## Fruit_sFig                     1.1471     1.6166   0.710
## Fruit_sGrape                  -3.4559     3.3977  -1.017
## Fruit_sRosehips               -2.6107     1.8268  -1.429
## Fruit_sStrawberry              0.5629     1.5815   0.356
## Fruit_sTomato                 -1.5720     1.8931  -0.830
## Generation                    -0.5607     0.7515  -0.746
## Fruit_sCherry:Generation       0.7404     0.7577   0.977
## Fruit_sCranberry:Generation    0.2725     0.7568   0.360
## Fruit_sFig:Generation          0.2539     0.7695   0.330
## Fruit_sGrape:Generation        1.6698     1.6622   1.005
## Fruit_sRosehips:Generation     1.3420     0.8714   1.540
## Fruit_sStrawberry:Generation   0.6427     0.7569   0.849
## Fruit_sTomato:Generation       1.1111     0.8785   1.265
## convergence code: 0
## boundary (singular) fit: see ?isSingular
emt1 <- emmeans::emtrends(mod_all_interaction, "Fruit_s", var = "Generation")
emt1          ### estimated slopes of Generation for each level of Fruit_s
##  Fruit_s      Generation.trend     SE     df lower.CL upper.CL
##  Blackcurrant           -0.561 0.7937   83.7  -2.1391   1.0177
##  Cherry                  0.180 0.0985 1460.0  -0.0135   0.3729
##  Cranberry              -0.288 0.0910 1415.8  -0.4666  -0.1097
##  Fig                    -0.307 0.1706  606.9  -0.6418   0.0282
##  Grape                   1.109 1.5179  105.0  -1.9006   4.1189
##  Rosehips                0.781 0.4558  116.4  -0.1214   1.6840
##  Strawberry              0.082 0.0921 1262.4  -0.0987   0.2627
##  Tomato                  0.550 0.4740  107.6  -0.3892   1.4900
## 
## Degrees-of-freedom method: kenward-roger 
## Confidence level used: 0.95
pairs(emt1)   ### comparison of slopes
##  contrast                  estimate    SE     df t.ratio p.value
##  Blackcurrant - Cherry      -0.7404 0.800   85.8 -0.926  0.9827 
##  Blackcurrant - Cranberry   -0.2725 0.799   85.5 -0.341  1.0000 
##  Blackcurrant - Fig         -0.2539 0.810   88.8 -0.313  1.0000 
##  Blackcurrant - Grape       -1.6698 1.669  103.4 -1.000  0.9734 
##  Blackcurrant - Rosehips    -1.3420 0.905   90.1 -1.483  0.8142 
##  Blackcurrant - Strawberry  -0.6427 0.799   85.5 -0.804  0.9924 
##  Blackcurrant - Tomato      -1.1111 0.910   86.7 -1.221  0.9235 
##  Cherry - Cranberry          0.4678 0.133 1205.0  3.505  0.0111 
##  Cherry - Fig                0.4865 0.196  703.8  2.481  0.2055 
##  Cherry - Grape             -0.9295 1.521  105.8 -0.611  0.9987 
##  Cherry - Rosehips          -0.6016 0.465  124.6 -1.294  0.8996 
##  Cherry - Strawberry         0.0977 0.134 1138.9  0.728  0.9962 
##  Cherry - Tomato            -0.3707 0.483  114.6 -0.768  0.9944 
##  Cranberry - Fig             0.0187 0.193  694.9  0.097  1.0000 
##  Cranberry - Grape          -1.3973 1.521  105.7 -0.919  0.9836 
##  Cranberry - Rosehips       -1.0694 0.464  123.5 -2.306  0.2990 
##  Cranberry - Strawberry     -0.3701 0.129 1112.5 -2.872  0.0792 
##  Cranberry - Tomato         -0.8385 0.481  113.7 -1.742  0.6600 
##  Fig - Grape                -1.4160 1.526  107.1 -0.928  0.9827 
##  Fig - Rosehips             -1.0881 0.482  132.2 -2.259  0.3242 
##  Fig - Strawberry           -0.3888 0.193  682.1 -2.013  0.4735 
##  Fig - Tomato               -0.8572 0.498  121.0 -1.721  0.6739 
##  Grape - Rosehips            0.3278 1.576  107.1  0.208  1.0000 
##  Grape - Strawberry          1.0271 1.521  105.7  0.675  0.9975 
##  Grape - Tomato              0.5588 1.578  107.2  0.354  1.0000 
##  Rosehips - Strawberry       0.6993 0.464  123.5  1.507  0.8023 
##  Rosehips - Tomato           0.2309 0.639   98.0  0.361  1.0000 
##  Strawberry - Tomato        -0.4684 0.482  113.7 -0.973  0.9774 
## 
## Degrees-of-freedom method: kenward-roger 
## P value adjustment: tukey method for comparing a family of 8 estimates

4.3 Plot

pd <- position_dodge(0.3) # move them .05 to the left and right

#Extract slope and intercept
dat_8fruits <- expand.grid(Generation=as.numeric(levels(as.factor(data_sum_allfruits_AN$Generation))),
                           Fruit_s=unique(data_sum_allfruits_AN$Fruit_s))
dat_8fruits$fitness_predicted <- predict(mod_all_interaction, newdata = dat_8fruits, 
                          re.form= NA, type = "response")





PLOT_CHERRY <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Cherry",], 
                            aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) + 
  geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
                width=.1,position = pd, size = 0.4,color = "black") + 
  geom_line(size = 0.5,position = pd) + 
  geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Cherry",],
                     aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) +
  geom_point(size = 2, position = pd, shape = 21, fill = "white",stroke = 1.2) + 
  ylim(-5.65, 1.25) +
  ylab("Fitness") + 
  xlab("Generation") + 
  xlim("1","2","3","4","5") +
  scale_color_manual(values = c("black", "#BC3C6D")) + 
  ggtitle("Cherry") + 
  theme_LO_adaptation + theme(plot.title = element_text(color = "#BC3C6D"))
PLOT_CHERRY

PLOT_CRANBERRY <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Cranberry",], 
                            aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) + 
  geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
                width=.1,position = pd, size = 0.4,color = "black") + 
  geom_line(size = 0.5,position = pd) + 
  geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Cranberry",],
                     aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) +
  geom_point(size = 2, position = pd, shape = 21, fill = "white",stroke = 1.2) + 
  ylim(-5.65, 1.25) +
  ylab("Fitness") + 
  xlim("1","2","3","4","5") +
  xlab("Generation") + 
  scale_color_manual(values = c("black","#FDB424")) + 
  ggtitle("Cranberry") + 
  theme_LO_adaptation + theme(plot.title = element_text(color = "#FDB424"))
PLOT_CRANBERRY

PLOT_STRAWBERRY <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Strawberry",], 
                            aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) + 
  geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
                width=.1,position = pd, size = 0.4,color = "black") + 
  geom_line(size = 0.5,position = pd) + 
  geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Strawberry",],
                     aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) +
  geom_point(size = 2, position = pd, shape = 21, fill = "white",stroke = 1.2) + 
  ylim(-5.65, 1.25) +
  xlim("1","2","3","4","5") +
  ylab("Fitness") + 
  xlab("Generation") + 
  scale_color_manual(values = c("black","#3FAA96")) + 
  ggtitle("Strawberry") + 
  theme_LO_adaptation + theme(plot.title = element_text(color = "#3FAA96"))
PLOT_STRAWBERRY

PLOT_GRAPE <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Grape",], 
                            aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) + 
  geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
                width=.1,position = pd, size = 0.4,color = "black") + 
  geom_line(size = 0.5,position = pd) + 
  geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Grape"&dat_8fruits$Generation == c(2,3),],
                     aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) +
  geom_point(size = 2, position = pd, shape = 21, fill = "white",stroke = 1.2) + 
  ylim(-5.65, 1.25) +
  xlim("1","2","3","4","5") +
  ylab("Fitness") + 
  xlab("Generation") + 
  scale_color_manual(values = c("black","#7B7554")) + 
  ggtitle("Grape") + 
  theme_LO_adaptation + theme(plot.title = element_text(color = "#7B7554"))
PLOT_GRAPE

PLOT_ROSEHIPS <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Rosehips",], 
                            aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) + 
  geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
                width=.1,position = pd, size = 0.4,color = "black") + 
  geom_line(size = 0.5,position = pd) + 
  geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Rosehips"&dat_8fruits$Generation != 5,],
                     aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) +
  geom_point(size = 2, position = pd, shape = 21, fill = "white",stroke = 1.2) + 
  ylim(-5.65, 1.25) +
  xlim("1","2","3","4","5") +
  ylab("Fitness") + 
  xlab("Generation") + 
  scale_color_manual(values = c("black","#8ACDEA")) + 
  ggtitle("Rose hips") + 
  theme_LO_adaptation + theme(plot.title = element_text(color = "#8ACDEA"))
PLOT_ROSEHIPS

PLOT_TOMATO <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Tomato",], 
                            aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) + 
  geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
                width=.1,position = pd, size = 0.4,color = "black") + 
  geom_line(size = 0.5,position = pd) + 
  geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Tomato"&dat_8fruits$Generation != 5,],
                     aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) +
  geom_point(size = 2, position = pd, shape = 21, fill = "white", stroke = 1.2) + 
  ylim(-5.65, 1.25) +
  xlim("1","2","3","4","5") +
  ylab("Fitness") + 
  xlab("Generation") + 
  scale_color_manual(values = c( "black","#ED6F47")) + 
  ggtitle("Tomato") + 
  theme_LO_adaptation + theme(plot.title = element_text(color = "#ED6F47"))
PLOT_TOMATO

PLOT_FIG <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Fig",], 
                            aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) + 
  geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
                width=.1,position = pd, size = 0.4,color = "black") + 
  geom_line(size = 0.5,position = pd) + 
  geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Fig"&dat_8fruits$Generation != 5,],
                     aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) +
  geom_point(size = 2, position = pd, shape = 21, fill = "white", stroke = 1.2) + 
  ylim(-5.65, 1.25) +
  xlim("1","2","3","4","5") +
  ylab("Fitness") + 
  xlab("Generation") + 
  scale_color_manual(values = c("black","#93194F")) + 
  ggtitle("Fig") + 
  theme_LO_adaptation + theme(plot.title = element_text(color = "#93194F"))
PLOT_FIG

PLOT_BLACKCURRANT <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Blackcurrant",], 
                            aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) + 
  geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
                width=.1,position = pd, size = 0.4,color = "black") + 
  geom_line(size = 0.5,position = pd) + 
  geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Blackcurrant"&dat_8fruits$Generation == c(2,3),],
                     aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) +
  geom_point(size = 2, position = pd, shape = 21, fill = "white", stroke = 1.2) + 
  ylim(-5.65, 1.25) +
  xlim("1","2","3","4","5") +
  ylab("Fitness") + 
  xlab("Generation") + 
  scale_color_manual(values = c( "black","#203753")) + 
  ggtitle("Blackcurrant") + 
  theme_LO_adaptation + theme(plot.title = element_text(color = "#203753"))
PLOT_BLACKCURRANT

DYNAMIC_EIGHT_JOIN <- cowplot::ggdraw() + 
  cowplot::draw_plot(PLOT_STRAWBERRY, x = 0, y = 0, width = 0.5, height = 0.28) + 
  cowplot::draw_plot(PLOT_GRAPE+ theme(axis.title.x = element_blank(),
                                              axis.text.x = element_blank(),
                                              axis.ticks.x = element_blank(),
                                              axis.line.x = element_blank()),
                     x = 0, y = 0.28, width = 0.5, height = 0.23) + 
  cowplot::draw_plot(PLOT_CRANBERRY+ theme(axis.title.x = element_blank(),
                                              axis.text.x = element_blank(),
                                              axis.ticks.x = element_blank(),
                                              axis.line.x = element_blank()),
                     x = 0, y = 0.53, width = 0.5, height = 0.23) + 
  cowplot::draw_plot(PLOT_BLACKCURRANT+ theme(axis.title.x = element_blank(),
                                              axis.text.x = element_blank(),
                                              axis.ticks.x = element_blank(),
                                              axis.line.x = element_blank()),
                     x = 0, y = 0.77, width = 0.5, height = 0.23) + 
  cowplot::draw_plot(PLOT_TOMATO+ theme(axis.title.y = element_blank()), 
                     x = 0.5, y = 0, width = 0.5, height = 0.28) + 
  cowplot::draw_plot(PLOT_ROSEHIPS+ theme(axis.title.y = element_blank(),
                                              axis.title.x = element_blank(),
                                              axis.text.x = element_blank(),
                                              axis.ticks.x = element_blank(),
                                              axis.line.x = element_blank()),
                     x = 0.5, y = 0.28, width = 0.5, height = 0.23) + 
  cowplot::draw_plot(PLOT_FIG+ theme(axis.title.y = element_blank(),
                                              axis.title.x = element_blank(),
                                              axis.text.x = element_blank(),
                                              axis.ticks.x = element_blank(),
                                              axis.line.x = element_blank()),
                     x = 0.5, y = 0.53, width = 0.5, height = 0.23) + 
  cowplot::draw_plot(PLOT_CHERRY + theme(axis.title.y = element_blank(),
                                              axis.title.x = element_blank(),
                                              axis.text.x = element_blank(),
                                              axis.ticks.x = element_blank(),
                                              axis.line.x = element_blank()),
                     x = 0.5, y = 0.77, width = 0.5, height = 0.23) +
  cowplot::draw_plot_label(c("A", "C",  "E", "G", "B",  "D", "F",  "H"),  
                  x = c(0, 0, 0, 0, 0.5, 0.5, 0.5, 0.5), 
                  y = c(1, 0.75, 0.50, 0.27, 1, 0.75, 0.5, 0.27), 
                  hjust = c(-0.5, -0.5, -0.5,-0.5, -0.5, -0.5, -0.5, -0.5), 
                  vjust = c(1.5, 1.5, 1.5,1.5, 1.5, 1.5,1.5, 1.5),
                  size = 12) 
 DYNAMIC_EIGHT_JOIN

cowplot::save_plot(file =here::here("figures", "SUPMAT_Fitness8Fruits.pdf"), DYNAMIC_EIGHT_JOIN, base_height = 17/cm(1), base_width = 15/cm(1), dpi = 1200)

5 SUP: Pooling effect

5.1 Data

########### Hypothesis 1 
#Hypothesis 1: effect of pool 
#Take the mean of all populations for each selection fruit 
 
CheCran_hypo1 <- computelogchange_POOL_hypo1(data_G7, "Cherry", "Cranberry")



########### Hypothesis 2 
#Hypothesis 2: effect of pool 
#Take the fitness difference of the population with the highest fitness in G7 
TEMP_dataG7_CheCran <- formattinglogchange(data_logchange, "7", "Cherry", "Cranberry")
fittest_lines<-computelogchange_POOL_hypo2(data_G7, "Cherry", "Cranberry")
CheCran_hypo2<-TEMP_dataG7_CheCran[TEMP_dataG7_CheCran$Line==fittest_lines,]

5.2 Plot

#Initial plot from main text
ymin = -50
ymax = 50



# Limits
ymin_CheCranG29=min(min(TEMP_dataG29_CheCran$logchange_allop-1.96*TEMP_dataG29_CheCran$sd_allop, na.rm= TRUE),
                min(TEMP_dataG29_CheCran$logchange_symp-1.96*TEMP_dataG29_CheCran$sd_symp, na.rm= TRUE))
ymax_CheCranG29=max(max(TEMP_dataG29_CheCran$logchange_allop + 1.96*TEMP_dataG29_CheCran$sd_allop, na.rm= TRUE),
                max(TEMP_dataG29_CheCran$logchange_symp + 1.96*TEMP_dataG29_CheCran$sd_symp, na.rm= TRUE))


CheCran_G29 <- ggplot(data = TEMP_dataG29_CheCran) + 
  geom_errorbar(aes(x =logchange_symp, ymin = logchange_allop-(1.96*sd_allop), 
                    ymax = logchange_allop + (1.96*sd_allop),
                    color = Symp),
                  width= 0.02, size = 0.3, alpha = 0.8) + 
  geom_errorbarh(aes(y = logchange_allop, xmin = logchange_symp-1.96*sd_symp, xmax = logchange_symp + 1.96*sd_symp, 
                 color = Symp),
                 height = 0.02, size = 0.3, alpha = 0.8) + 
  geom_point(aes(x =logchange_symp, y = logchange_allop,  color = Symp,fill = Symp, shape = Allop),
                 size =3, fill = "white", stroke =1.2) + 
  xlab("Fitness difference in\nselective environment")  + 
  ylab("Fitness difference in\nalternative environment")  + 
  ggtitle("Cherry vs. Cranberry") + 
  labs(shape = "Test fruit", color = "Evolution fruit") + 
  scale_shape_manual(values = c(16, 15)) + 
  scale_color_manual(values = c("#BC3C6D", "#FDB424"))  + 
  coord_cartesian(ylim = c(ymin_CheCranG29, ymax_CheCranG29), 
                  xlim = c(ymin_CheCranG29, ymax_CheCranG29)) + 
  theme_LO_sober
 CheCran_G29

PLOT_HYPO_1<-CheCran_G29 +  
  geom_errorbar(data = CheCran_hypo1, aes(x =logchange_symp, ymin = logchange_allop-(1.96*sd_allop), 
                    ymax = logchange_allop + (1.96*sd_allop),
                    color = Symp),
                  width= 0.02, size = 0.2, alpha =1) + 
  geom_errorbarh(data = CheCran_hypo1, 
                 aes(y = logchange_allop, xmin = logchange_symp-1.96*sd_symp, xmax = logchange_symp + 1.96*sd_symp, 
                 color = Symp),
                 height = 0.02, size = 0.2, alpha =1) + 
  geom_point(data = CheCran_hypo1,
             aes(x =logchange_symp, y = logchange_allop,  color = Symp,fill = Symp, shape = Allop),
                 size = 6, fill = "white", stroke = 2) +
    geom_point(data = CheCran_hypo1,
             aes(x =logchange_symp, y = logchange_allop,  fill = Symp, shape = Allop),
                 size = 3, fill = "white", color = "white", stroke = 2) +
  ggtitle("Hypothesis 1: Mean of populations effect")
PLOT_HYPO_1

PLOT_HYPO_2<-CheCran_G29 +  
  geom_errorbar(data = CheCran_hypo2, aes(x = logchange_symp, 
                                          ymin = logchange_allop-(1.96*sd_allop), 
                    ymax = logchange_allop + (1.96*sd_allop),
                    color = Symp),
                  width= 0.02, size = 0.2, alpha =1) + 
  geom_errorbarh(data = CheCran_hypo2, 
                 aes(y = logchange_allop, xmin = logchange_symp-1.96*sd_symp, xmax = logchange_symp + 1.96*sd_symp, 
                 color = Symp),
                 height = 0.02, size = 0.2, alpha =1) + 
  geom_point(data = CheCran_hypo2,
             aes(x =logchange_symp, y = logchange_allop,  color = Symp,fill = Symp, shape = Allop),
                 size = 6, fill = "white", stroke = 2) +
    geom_point(data = CheCran_hypo2,
             aes(x = logchange_symp, y = logchange_allop,  fill = Symp, shape = Allop),
                 size = 3, fill = "white", color = "white", stroke = 2) +
  ggtitle("Hypothesis 2: Fittest population effect")
PLOT_HYPO_2

#legend1
legend_tradevide<- ggplot(CheCran_hypo2, aes(x=logchange_symp, y=logchange_allop, group=Fruit_s, colour=Fruit_s)) +
  geom_point(size=1.5, position=pd, fill="white", alpha=0.6) + 
  geom_errorbar(aes(ymin=logchange_allop-(1.96*sd_allop), ymax=logchange_allop+(1.96*sd_allop),),
                  width=0.4,size=0.4, alpha=0.3) +
  labs(colour = "Population \nevolved on:") + 
  scale_color_manual(values=c("#BC3C6D", "#FDB424","#3FAA96"), 
                     label=c("Cherry","Cranberry", "Strawberry")) +   
  theme_LO_sober +
  theme(legend.title = element_text(colour="black", size=10, face="bold"), 
          legend.text = element_text(colour="black", size=8))

legend_tradevide<-lemon::g_legend(legend_tradevide)

 #legend hypo 1
legend_hypo1<- ggplot(CheCran_hypo2, aes(x=logchange_symp, y=logchange_allop, group=Fruit_s, colour=Fruit_s)) +
  geom_point(size=1.5, position=pd, fill="white", alpha=0.6) + 
  geom_errorbar(aes(ymin=logchange_allop-(1.96*sd_allop), ymax=logchange_allop+(1.96*sd_allop),),
                  width=0.4,size=0.4, alpha=0.3) +
  labs(colour = "Mean of population\nevolved on:") + 
  geom_point(size=2, shape=21, fill="white", stroke = 2) + 
  scale_color_manual(values=c("#BC3C6D", "#FDB424","#3FAA96"), 
                     label=c("Cherry","Cranberry", "Strawberry")) +   
  theme_LO_sober +
  theme(legend.title = element_text(colour="black", size=10, face="bold"), 
          legend.text = element_text(colour="black", size=8))

extract_legend_hypo1<-lemon::g_legend(legend_hypo1)

 #legend2
legend_hypo2<- ggplot(CheCran_hypo2, aes(x=logchange_symp, y=logchange_allop, group=Fruit_s, colour=Fruit_s)) +
  geom_point(size=1.5, position=pd, fill="white", alpha=0.6) + 
  geom_errorbar(aes(ymin=logchange_allop-(1.96*sd_allop), ymax=logchange_allop+(1.96*sd_allop),),
                  width=0.4,size=0.4, alpha=0.3) +
  labs(colour = "Population with \nthe highest fitness \non each selection fruit:") + 
  geom_point(size=2, shape=21, fill="white", stroke = 2) + 
  scale_color_manual(values=c("#BC3C6D", "#FDB424","#3FAA96"), 
                     label=c("Cherry","Cranberry", "Strawberry")) +   
  theme_LO_sober +
  theme(legend.title = element_text(colour="black", size=10, face="bold"), 
          legend.text = element_text(colour="black", size=8))

extract_legend_hypo2<-lemon::g_legend(legend_hypo2)



ERRORCROSSES_G7_HYPO1_2 <- cowplot::ggdraw() +
  cowplot::draw_plot(PLOT_HYPO_1+theme(legend.position = "none"), 
            x =0.00, y = 0.5, width = 0.75, height = 0.5) +
  cowplot::draw_plot(PLOT_HYPO_2+theme(legend.position = "none"), 
            x = 0.0, y = 0, width = 0.75, height = 0.5) +
  cowplot::draw_plot(legend_tradevide, x = 0.78, y = 0.85, width = 0.1, height = 0.1) +
  cowplot::draw_plot(extract_legend_hypo1, x = 0.82, y = 0.7, width = 0.1, height = 0.1) +
  cowplot::draw_plot(legend_tradevide, x = 0.76, y = 0.35, width = 0.1, height = 0.1) +
  cowplot::draw_plot(extract_legend_hypo2, x = 0.82, y = 0.2, width = 0.1, height = 0.1) 
ERRORCROSSES_G7_HYPO1_2

cowplot::save_plot(file =here::here("figures", "SUPMAT_Pooleffect_Hypothesis.pdf"),
                   ERRORCROSSES_G7_HYPO1_2,
                   base_height = 18/cm(1), base_width = 15/cm(1), dpi = 610)

5.3 Extra plot

PAIR_StrawChe_G29

PAIR_CranStraw_G29

PAIR_CheCran_G29

## Data
# EC_Cran_Cher_G7<-formattingplotpair(data_logchange, "7", "Cherry", "Cranberry")
# EC_Straw_Cran_G7<-formattingplotpair(data_logchange, "7", "Cranberry", "Strawberry")
# EC_Straw_Cher_G7<-formattingplotpair(data_logchange, "7", "Strawberry", "Cherry")

########### Hypothesis 1 
#Hypothesis 1: effect of pool 
#Take the mean of all populations for each selection fruit 
dataset_hypo1 <- formatting_POOL_hypo1(fitness_dataset_intermediate = data_G7)

########### Hypothesis 2 
#Hypothesis 2: effect of pool 
#Take the fitness difference of the population with the highest fitness in G7 
fittest_lines<-formatting_POOL_hypo2(data_G7)
EC_Cran_Cher_hypo2<-EC_Cran_Cher_G7[EC_Cran_Cher_G7$Line == fittest_lines[1]|
                                      EC_Cran_Cher_G7$Line == fittest_lines[2]|
                                      EC_Cran_Cher_G7$Line == fittest_lines[3],]
EC_Straw_Cran_hypo2<-EC_Straw_Cran_G7[EC_Straw_Cran_G7$Line == fittest_lines[1]|
                                       EC_Straw_Cran_G7$Line == fittest_lines[2]|
                                        EC_Straw_Cran_G7$Line == fittest_lines[3],]
EC_Straw_Cher_hypo2<-EC_Straw_Cher_G7[EC_Straw_Cher_G7$Line == fittest_lines[1]|
                                       EC_Straw_Cher_G7$Line == fittest_lines[2]|
                                        EC_Straw_Cher_G7$Line == fittest_lines[3],]


PAIR_CheCran_G29_HYPO_1 <- PAIR_CheCran_G29 +
  geom_errorbar(data = dataset_hypo1, 
                aes(x=logchange_Strawberry, 
                    ymin = logchange_Cranberry-1.96*sd_logchange_Cranberry,
                    ymax = logchange_Cranberry+1.96*sd_logchange_Cranberry, Line=NA),
                width=0.02, size=0.2, alpha=1) + 
  geom_errorbarh(data = dataset_hypo1, 
                 aes(y=logchange_Cranberry, 
                     xmin = logchange_Strawberry-1.96*sd_logchange_Strawberry,
                     xmax = logchange_Strawberry+1.96*sd_logchange_Strawberry),
                 height=0.02, size=0.2, alpha=1) + 
  geom_point(data = dataset_hypo1, 
             aes(x = logchange_Strawberry, y = logchange_Cranberry), 
             shape=21, size=4,  fill = "#ffffff", stroke=1.5)
PAIR_CheCran_G29_HYPO_1

PAIR_StrawChe_G29_HYPO_1<-PAIR_StrawChe_G29 +
  geom_errorbar(data = dataset_hypo1, 
                aes(x=logchange_Strawberry, 
                    ymin = logchange_Cranberry-1.96*sd_logchange_Cranberry,
                    ymax = logchange_Cranberry+1.96*sd_logchange_Cranberry, Line=NA),
                width=0.02, size=0.2, alpha=1) + 
  geom_errorbarh(data = dataset_hypo1, 
                 aes(y=logchange_Cranberry, 
                     xmin = logchange_Strawberry-1.96*sd_logchange_Strawberry,
                     xmax = logchange_Strawberry+1.96*sd_logchange_Strawberry),
                 height=0.02, size=0.2, alpha=1) + 
  geom_point(data = dataset_hypo1, 
             aes(x = logchange_Strawberry, y = logchange_Cranberry), 
             shape=21, size=4,  fill = "#ffffff", stroke=1.5)
PAIR_StrawChe_G29_HYPO_1

PAIR_CranStraw_G29_HYPO_1<-PAIR_StrawChe_G29  + 
  geom_errorbar(data = dataset_hypo1, 
                aes(x=logchange_Strawberry, 
                    ymin = logchange_Cranberry-1.96*sd_logchange_Cranberry,
                    ymax = logchange_Cranberry+1.96*sd_logchange_Cranberry, Line=NA),
                width=0.02, size=0.2, alpha=1) + 
  geom_errorbarh(data = dataset_hypo1, 
                 aes(y=logchange_Cranberry, 
                     xmin = logchange_Strawberry-1.96*sd_logchange_Strawberry,
                     xmax = logchange_Strawberry+1.96*sd_logchange_Strawberry),
                 height=0.02, size=0.2, alpha=1) + 
  geom_point(data = dataset_hypo1, 
             aes(x = logchange_Strawberry, y = logchange_Cranberry), 
             shape=21, size=4,  fill = "#ffffff", stroke=1.5)
PAIR_CranStraw_G29_HYPO_1

PAIR_CranStraw_G29_HYPO_2 <- PAIR_CranStraw_G29 +
  geom_errorbar(data = EC_Straw_Cran_hypo2, 
                aes(x=logchange_Strawberry, 
                    ymin = logchange_Cranberry-1.96*sd_logchange_Cranberry,
                    ymax = logchange_Cranberry+1.96*sd_logchange_Cranberry),
                width=0.02, size=0.2, alpha=1) + 
  geom_errorbarh(data = EC_Straw_Cran_hypo2, 
                 aes(y=logchange_Cranberry, 
                     xmin = logchange_Strawberry-1.96*sd_logchange_Strawberry,
                     xmax = logchange_Strawberry+1.96*sd_logchange_Strawberry),
                 height=0.02, size=0.2, alpha=1) + 
  geom_point(data = EC_Straw_Cran_hypo2, 
             aes(x = logchange_Strawberry, y = logchange_Cranberry), 
             shape=21, size=4,  fill = "#ffffff", stroke=1.5)
PAIR_CranStraw_G29_HYPO_2

PAIR_StrawChe_G29_HYPO_2 <- PAIR_StrawChe_G29 +
  geom_errorbar(data = EC_Straw_Cher_hypo2, 
                aes(x=logchange_Cherry, 
                    ymin = logchange_Strawberry-1.96*sd_logchange_Strawberry,
                    ymax = logchange_Strawberry+1.96*sd_logchange_Strawberry),
                width=0.02, size=0.2, alpha=1) + 
  geom_errorbarh(data = EC_Straw_Cher_hypo2, 
                 aes(y=logchange_Strawberry, 
                     xmin = logchange_Cherry-1.96*sd_logchange_Cherry,
                     xmax = logchange_Cherry+1.96*sd_logchange_Cherry),
                 height=0.02, size=0.2, alpha=1) + 
  geom_point(data = EC_Straw_Cher_hypo2, 
             aes(x = logchange_Cherry, y = logchange_Strawberry), 
             shape=21, size=4,  fill = "#ffffff", stroke=1.5)
PAIR_StrawChe_G29_HYPO_2

PAIR_CheCran_G29_HYPO_2<-PAIR_CheCran_G29  + 
  geom_errorbar(data = EC_Cran_Cher_hypo2, 
                aes(x=logchange_Cranberry, 
                    ymin = logchange_Cherry-1.96*sd_logchange_Cherry,
                    ymax = logchange_Cherry+1.96*sd_logchange_Cherry),
                width=0.02, size=0.2, alpha=1) + 
  geom_errorbarh(data = EC_Cran_Cher_hypo2, 
                 aes(y=logchange_Cherry, 
                     xmin = logchange_Cranberry-1.96*sd_logchange_Cranberry,
                     xmax = logchange_Cranberry+1.96*sd_logchange_Cranberry),
                 height=0.02, size=0.2, alpha=1) + 
  geom_point(data = EC_Cran_Cher_hypo2, 
             aes(x = logchange_Cranberry, y = logchange_Cherry), 
             shape=21, size=4,  fill = "#ffffff", stroke=1.5)
PAIR_CheCran_G29_HYPO_2

#legend1
legend_tradevide<- ggplot(EC_Cran_Cher_hypo2, aes(x=logchange_Cranberry, 
                                                  y=logchange_Cherry, group=Fruit_s, colour=Fruit_s)) +
  geom_point(size=1.5, position=pd, fill="white", alpha=0.6) + 
  labs(colour = "Population \nevolved on:") + 
  scale_color_manual(values=c("#BC3C6D", "#FDB424","#3FAA96"), 
                     label=c("Cherry","Cranberry", "Strawberry")) +   
  theme_LO_sober +
  theme(legend.title = element_text(colour="black", size=10, face="bold"), 
          legend.text = element_text(colour="black", size=8))

legend_tradevide<-lemon::g_legend(legend_tradevide)

 #legend hypo 1
legend_hypo1<- ggplot(EC_Cran_Cher_hypo2, aes(x=logchange_Cranberry, 
                                                  y=logchange_Cherry, group=Fruit_s, colour=Fruit_s)) +
  geom_point(size=1.5, position=pd, fill="white", alpha=0.6) + 
  labs(colour = "Mean of population\nevolved on:") + 
  geom_point(size=2, shape=21, fill="white", stroke = 2) + 
  scale_color_manual(values=c("#BC3C6D", "#FDB424","#3FAA96"), 
                     label=c("Cherry","Cranberry", "Strawberry")) +   
  theme_LO_sober +
  theme(legend.title = element_text(colour="black", size=10, face="bold"), 
          legend.text = element_text(colour="black", size=8))

extract_legend_hypo1<-lemon::g_legend(legend_hypo1)

 #legend2
legend_hypo2<- ggplot(EC_Cran_Cher_hypo2, aes(x=logchange_Cranberry, 
                                                  y=logchange_Cherry, group=Fruit_s, colour=Fruit_s)) +
  geom_point(size=1.5, position=pd, fill="white", alpha=0.6) + 
  labs(colour = "Population with \nthe highest fitness \non each selection fruit:") + 
  geom_point(size=2, shape=21, fill="white", stroke = 2) + 
  scale_color_manual(values=c("#BC3C6D", "#FDB424","#3FAA96"), 
                     label=c("Cherry","Cranberry", "Strawberry")) +   
  theme_LO_sober +
  theme(legend.title = element_text(colour="black", size=10, face="bold"), 
          legend.text = element_text(colour="black", size=8))
extract_legend_hypo2<-lemon::g_legend(legend_hypo2)




ERRORCROSSES_G7_HYPO1 <- cowplot::ggdraw() +
  cowplot::draw_plot(PAIR_CheCran_G29_HYPO_1+theme(legend.position = "none"), 
            x =0.00, y = 0, width = 0.25, height = 1) +
  cowplot::draw_plot(PAIR_CranStraw_G29_HYPO_1+theme(legend.position = "none"), 
            x = 0.26, y = 0, width = 0.25, height = 1) +
  cowplot::draw_plot(PAIR_StrawChe_G29_HYPO_1+theme(legend.position = "none"), 
            x = 0.52, y = 0, width = 0.25, height = 1) + 
  cowplot::draw_plot(legend_tradevide, x = 0.8, y = 0.73, width = 0.11, height = 0.1) +
  cowplot::draw_plot(extract_legend_hypo1, x = 0.83, y = 0.25, width = 0.1, height = 0.1) 
ERRORCROSSES_G7_HYPO1

ERRORCROSSES_G7_HYPO2 <- cowplot::ggdraw() +
  cowplot::draw_plot(PAIR_CheCran_G29_HYPO_2+theme(legend.position = "none"), 
            x =0.00, y = 0, width = 0.25, height = 1) +
  cowplot::draw_plot(PAIR_CranStraw_G29_HYPO_2+theme(legend.position = "none"), 
            x = 0.26, y = 0, width = 0.25, height = 1) +
  cowplot::draw_plot(PAIR_StrawChe_G29_HYPO_2+theme(legend.position = "none"), 
            x = 0.52, y = 0, width = 0.25, height = 1) + 
  cowplot::draw_plot(legend_tradevide, x = 0.78, y = 0.73, width = 0.1, height = 0.1) +
  cowplot::draw_plot(extract_legend_hypo2, x = 0.82, y = 0.25, width = 0.1, height = 0.1) 
ERRORCROSSES_G7_HYPO2

# 
# cowplot::save_plot(file =here::here("figures", "SUPMAT_Pool_Hypothesis1.pdf"),
#                    ERRORCROSSES_G7_HYPO1,
#                    base_height = 7/cm(1), base_width = 28/cm(1), dpi = 610)
# 
# 
# cowplot::save_plot(file =here::here("figures", "SUPMAT_Pool_Hypothesis2.pdf"),
#                    ERRORCROSSES_G7_HYPO2,
#                    base_height = 7/cm(1), base_width = 28/cm(1), dpi = 610)